﻿<%@ Page Title="Agent Master" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="AgentMgmt.aspx.cs" Inherits="TestJQGrid.AgentMgmt" %>

<%@ Register Assembly="Trirand.Web" TagPrefix="trirand" Namespace="Trirand.Web.UI.WebControls" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title></title>
    <!-- The jQuery UI theme that will be used by the grid -->
    <link rel="stylesheet" type="text/css" media="screen" href="../themes/redmond/jquery-ui-1.8.2.custom.css" />
    <!-- The jQuery UI theme extension jqGrid needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="../themes/ui.jqgrid.css" />
    <!-- jQuery runtime minified -->
    <script src="../js/jquery-1.4.4.min.js" type="text/javascript"></script>
    <!-- The localization file we need, English in this case -->
    <script src="../js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script>
    <!-- The jqGrid client-side javascript -->
    <script src="../js/trirand/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="../js/trirand/jquery.jqDatePicker.min.js" type="text/javascript"></script>
    <style type="text/css">
        .style3
        {
            width: 925px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table border="1px">
        <tr style="width:100%;">
            <td align="center" valign="middle" class="style3">
                <asp:Label ID="Label2" runat="server" Text="Agent Master" Font-Size="Medium"></asp:Label>
            </td>
        </tr>
        <tr style="width:100%;">
            <td class="style3">
                <trirand:JQGrid runat="server" ID="JQGrid1" DataSourceID="SqlDataSource1" AutoWidth="True"
                    Height="300px" Width="890px">
                    <Columns>
                        <trirand:JQGridColumn Editable="true" DataField="AgentId" PrimaryKey="True" />
                        <trirand:JQGridColumn Editable="true" DataField="AgentName" />
                        <trirand:JQGridColumn Editable="true" DataField="PAN" />
                        <trirand:JQGridColumn Editable="false" DataField="ProductName" PrimaryKey="True" />
                        <trirand:JQGridColumn Editable="true" DataField="Status" EditType="DropDown" EditorControlID="StatusValues" />
                        <trirand:JQGridColumn Editable="true" DataField="DateOfJoining" DataType="System.DateTime"
                            DataFormatString="{0:dd/MM/yyyy}" EditType="DatePicker" EditorControlID="datepicker" />
                        <trirand:JQGridColumn Editable="true" DataField="TaxPercent" />
                        <trirand:JQGridColumn Editable="false" DataField="CreatedBy" />
                        <trirand:JQGridColumn Editable="false" DataField="CreatedOn" DataType="System.DateTime"
                            DataFormatString="{0:dd/MM/yyyy}" />
                    </Columns>
                    <EditDialogSettings CloseAfterEditing="True" ReloadAfterSubmit="true" />
                    <AddDialogSettings CloseAfterAdding="true" ReloadAfterSubmit="true" />
                    <SearchDialogSettings MultipleSearch="True" />
                    <ToolBarSettings ShowEditButton="true" ShowRefreshButton="True" ShowAddButton="true"
                        ShowSearchButton="True" ShowViewRowDetailsButton="True" />
                    <SortSettings InitialSortColumn="AgentId"></SortSettings>
                    <AppearanceSettings ShowRowNumbers="True" />
                </trirand:JQGrid>
                <asp:SqlDataSource runat="server" ID="StatusDataSource" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
                    SelectCommand="Select [Value] from [ValidValues] where [TableName] IN ( select [AgentAccess] from [Permissions] where [UserId] = 'abc' and [ProductName] = 'CarSales' ) and [ColumnName] = 'Status'" />
                <asp:DropDownList runat="server" ID="StatusValues" DataSourceID="StatusDataSource"
                    DataValueField="Value" DataTextField="Value" />
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
                    SelectCommand="SELECT [AgentId], [AgentName], [PAN], [ProductName], [Status], [DateOfJoining], [TaxPercent], [CreatedBy], [CreatedOn] FROM [Agents] where [ProductName] = @ProductName AND [Status] IN ( Select [Value] from [ValidValues] where [TableName] IN 
        ( select [AdminAccess] from [Permissions] where [UserId] = @loginId and [ProductName] = @ProductName ) and [ColumnName] = 'Visible' )"
                    InsertCommand="INSERT INTO [Agents] ([AgentId], [AgentName], [PAN], [ProductName], [Status], [DateOfJoining], [TaxPercent], [CreatedBy], [CreatedOn]) 
            VALUES (@AgentId, @AgentName, @PAN, @ProductName, @Status, @DateOfJoining, @TaxPercent, @loginId, getDate() )"
                    UpdateCommand="UPDATE [Agents] SET [AgentName] = @AgentName, [PAN] = @PAN, [Status] = @Status, [DateOfJoining] = @DateOfJoining, [TaxPercent] = @TaxPercent 
            WHERE [AgentId] = @AgentId AND [ProductName] = @ProductName" DeleteCommand="DELETE FROM [Agents] WHERE [AgentId] = @AgentId AND [ProductName] = @ProductName">
                    <SelectParameters>
                        <asp:SessionParameter DefaultValue="'default'" Name="loginId" Type="String" SessionField="loginId" />
                        <asp:SessionParameter DefaultValue="'default'" Name="ProductName" Type="String" SessionField="ProductName" />
                    </SelectParameters>
                    <DeleteParameters>
                        <asp:Parameter Name="AgentId" Type="Decimal" />
                        <asp:Parameter Name="ProductName" Type="String" />
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:SessionParameter DefaultValue="'default'" Name="loginId" Type="String" SessionField="loginId" />
                        <asp:SessionParameter DefaultValue="'default'" Name="ProductName" Type="String" SessionField="ProductName" />
                        <asp:Parameter Name="AgentId" Type="Decimal" />
                        <asp:Parameter Name="AgentName" Type="String" />
                        <asp:Parameter Name="PAN" Type="String" />
                        <asp:Parameter Name="Status" Type="String" />
                        <asp:Parameter Name="DateOfJoining" DbType="Date" />
                        <asp:Parameter Name="TaxPercent" DbType="Decimal" />
                    </InsertParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="AgentName" Type="String" />
                        <asp:Parameter Name="PAN" Type="String" />
                        <asp:Parameter Name="Status" Type="String" />
                        <asp:Parameter Name="DateOfJoining" DbType="Date" />
                        <asp:Parameter Name="TaxPercent" DbType="Decimal" />
                        <asp:Parameter Name="AgentId" Type="Decimal" />
                        <asp:SessionParameter DefaultValue="'default'" Name="ProductName" Type="String" SessionField="ProductName" />
                    </UpdateParameters>
                </asp:SqlDataSource>
                <trirand:JQDatePicker ID="datepicker" runat="server" DateFormat="dd/MM/yyyy" DisplayMode="ControlEditor" />
            </td>
        </tr>
    </table>
</asp:Content>
